/*
 * WyjsceFrame.java
 *
 * Created on 18 czerwiec 2008, 14:46
 */

package powierzchnie;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;

/**
 *
 * @author  arkadiusz
 */
public class WyjsceFrame extends javax.swing.JFrame {

    /** Creates new form WyjsceFrame */
    public WyjsceFrame(String tekst) {
        initComponents();
        this.jTextArea1.setText(tekst);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollPane1 = new java.awt.ScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        scrollPane1.add(jScrollPane1);

        getContentPane().add(scrollPane1, java.awt.BorderLayout.CENTER);

        jButton1.setText("Zapisz do pliku...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        BufferedWriter writer = null;
        try {
            JFileChooser jfc = new JFileChooser();
            jfc.showSaveDialog(this);
            File f = jfc.getSelectedFile();
            writer = new BufferedWriter(new FileWriter(f));//GEN-LAST:event_jButton1ActionPerformed
            writer.write(this.jTextArea1.getText());
        } catch(IOException ex) {
            Logger.getLogger(WyjsceFrame.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                writer.close();
            } catch(IOException ex) {
                Logger.getLogger(WyjsceFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
}

 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private java.awt.ScrollPane scrollPane1;
    // End of variables declaration//GEN-END:variables

}
